#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int jump(vector<int>& nums) {
    int n = nums.size();
    int left = 0, right = 0, maxpos = 0;
    int ret = 0;

    while (left <= right)
    {
        if (maxpos >= n - 1)
            return ret;
        for (int i = left; i <= right; ++i)
            maxpos = max(maxpos, nums[i] + i);
        left = right + 1;
        right = maxpos;
        ++ret;
    }

    return -1;
}

int main()
{
    vector<int> a = { 2,3,1,1,4 };

    jump(a);

	return 0;
}